package com.zb.goods.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.entity.SelectVo;
import com.zb.result.Result;
import com.zb.service.ZjGoodsUnitService;
import com.zb.utils.TokenUtil;
import com.zb.vo.GoodsUnitSelectVo;
import com.zb.vo.GoodsUnitVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 商品单位表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-08-01
 */
@Api(tags = "商品单位类接口")
@RestController
@RequestMapping("/goods/set/unit")
public class ZjGoodsUnitController {
    @Resource
    private ZjGoodsUnitService goodsUnitService;

    @SystemLog(moduleType = OperationLogModuleType.GOODS_MODULE_TYPE, type = OperationLogType.INSERT_UPDATE, remark = "商品设置-单位 - 新增或修改单位")
    @ApiOperation("新增或修改单位")
    @PostMapping("/save")
    public Result save(HttpServletRequest request, @RequestBody @Valid GoodsUnitVo unitVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        goodsUnitService.save(custAccId, unitVo);
        return Result.success(null == unitVo.getId()? "新增单位成功" : "修改单位成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.GOODS_MODULE_TYPE, type = OperationLogType.SELECT, remark = "商品设置-单位 - 获取商品单位列表")
    @ApiOperation("获取商品单位列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody GoodsUnitSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取商品单位列表成功").data(goodsUnitService.getList(custAccId, selectVo));
    }

    @SystemLog(moduleType = OperationLogModuleType.GOODS_MODULE_TYPE, type = OperationLogType.UPDATE, remark = "商品设置-单位 - 批量禁用或启用商品单位")
    @ApiOperation("批量禁用或启用商品单位")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "单位状态：false-启用，true-禁用", required = true, example = "false") boolean status,
                          @RequestBody @ApiParam(value = "商品单位ID集合", required = true) List<Long> idList) {
        goodsUnitService.updateBatchDisalbeByIds(idList, status);
        return Result.success(status? "禁用单位成功" : "启用单位成功");
    }

    @SystemLog(moduleType = OperationLogModuleType.GOODS_MODULE_TYPE, type = OperationLogType.DELETE, remark = "商品设置-单位 - 批量删除商品单位")
    @ApiOperation("批量删除商品单位")
    @DeleteMapping("/")
    public Result delete(@RequestBody @ApiParam(value = "商品单位ID集合", required = true) List<Long> idList) {
        goodsUnitService.delete(idList);
        return Result.success("删除单位成功");
    }



}
